# 构建可执行文件
function(build_executable)
        # 定义要解析的参数类型
        set(options       )                    # 布尔选项（如 VERBOSE, STATIC）
        set(oneValueArgs )                # 单值参数
        set(multiValueArgs
        BUILD_TARGET_NAME   # 构建目标名称
        OUT_NAME            # 输出名称
        VERSION             # 版本号
        SOURCES             # 源文件目录
        INCLUDES            # 头文件目录
        PACKAGE_DESCRIPTION # 包描述
        PACKAGE_MAINTAINER  # 包维护者
        )  # 多值参数
        # 解析参数
        cmake_parse_arguments(ARGV "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
       # 收集源文件
       file(GLOB_RECURSE SRC
           ${ARGV_SOURCES}/*.cpp
           ${ARGV_SOURCES}/*.c
           ${ARGV_INCLUDES}/*.h
           ${ARGV_INCLUDES}/*.hpp
       )
        # 添加可执行文件
        add_executable(${ARGV_BUILD_TARGET_NAME} ${SRC})

        # 设置目标属性
        set_target_properties(${ARGV_BUILD_TARGET_NAME} PROPERTIES
            # 输出文件名（例如：myapp -> myrunner）
            OUTPUT_NAME ${ARGV_OUT_NAME}
            # 版本信息（可选，某些平台有用）
            VERSION ${ARGV_VERSION}
            SOVERSION 1
            # 包含头文件目录
            INCLUDE_DIRECTORIES ${ARGV_INCLUDES}
            # 编译宏定义
            COMPILE_DEFINITIONS "APP_VERSION=\"${ARGV_VERSION}\";USE_LOGGER"
            # C++ 标准（也可用 target_compile_features）
            CXX_STANDARD 17
            CXX_STANDARD_REQUIRED ON
            CXX_EXTENSIONS OFF
        )
    # 安装目标
    install(TARGETS ${ARGV_BUILD_TARGET_NAME} RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)
    # 安装头文件
    install(DIRECTORY ${ARGV_INCLUDES} DESTINATION include)

    # 包含 CPack 模块
    include(InstallRequiredSystemLibraries)
    set(CPACK_PACKAGE_NAME ${ARGV_BUILD_TARGET_NAME})  # 包名称
    set(CPACK_PACKAGE_VERSION ${ARGV_VERSION})  # 包版本
    set(CPACK_PACKAGE_DESCRIPTION ${ARGV_PACKAGE_DESCRIPTION})  # 包描述
    set(CPACK_DEBIAN_PACKAGE_MAINTAINER ${ARGV_PACKAGE_MAINTAINER})  # 设置维护者信息
    set(CPACK_GENERATOR "DEB")  # 指定生成器为 DEB
    set(CPACK_DEBIAN_PACKAGE_SECTION "utils")  # Debian 包所属的软件分类
    set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.14)")  # 依赖项
    #set(CPACK_DEBIAN_PACKAGE_DEPENDS "libmylib-dev")  # 指定依赖的包名
    set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")  # 包优先级
    # 设置默认的安装路径（这对于一些生成器很重要）
    set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
    include(CPack)
endfunction()
